var imgurl;
window.document.oncontextmenu = function() { return false; }
window.document.onselectstart = function() { return false; }
document.onkeydown = function(e) { if(e.keyCode!=122) return false; }

function xmlhttprequest(url) {
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function(data) {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				console.info(xhr.responseText);
				var data = JSON.parse(xhr.responseText);
				document.title = data.images[0].copyright;
				imgurl="http://www.bing.com" + data.images[0].url;
				document.body.style.backgroundImage="url("+imgurl+")";
			} else {
				console.error(xhr.responseText);
			}
		}
	}
	xhr.open('GET', url, true);
	xhr.send();
}

xmlhttprequest('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');                

function drawclock() {
	var day = ["日","一","二","三","四","五","六"];
	var date = new Date();
	var y = date.getFullYear();
	var mo = date.getMonth()+1;
	var d = date.getDate();
	var h = date.getHours();
	//var s = date.getSeconds();
	var m = date.getMinutes();
	var th = h < 10 ? "0" + h : h;
	var tm = m < 10 ? "0" + m : m;
	//var ts=s<10?"0"+s:s;
	document.getElementById("date").innerHTML = y + " " + mo + " " + d + " " + day[date.getDay()];
	document.getElementById("time").innerHTML = th + ":" + tm;
}

function download() {
	var link = document.createElement('a');
	var fn = imgurl.substring(imgurl.lastIndexOf('/') + 1);
	link.download = fn;
	link.href = imgurl;
	link.click();
}

document.getElementById('time').onmouseover = function(){
	document.getElementById('date').style.opacity=0.7;
};

document.getElementById('time').onmouseout = function(){
	document.getElementById('date').style.opacity=0.0;
};

document.getElementById('time').onmouseover = function(){
	document.getElementById('date').style.opacity=0.7;
};

document.getElementById('time').onfocus = function(){
	//console.log('time onfocus');
	this.blur();
};

document.getElementById('time').onclick= function(){
	download();
};

drawclock();	
setInterval(function(){drawclock();},60000);